package top.datacluster.basic.offer;

public class Fibonacci {

    public static void main(String[] args) {
        System.out.println(get(7));
    }

    public static int get(int n){
        if (n < 0){
            throw new IllegalArgumentException();
        }
        if (n == 0){
            return 0;
        }
        if (n == 1){
            return 1;
        }
        int fibonacci0 = 0;
        int fibonacci1 = 1;
        int i = 2;
        int temp = 0;
        while (i <= n){
            temp = fibonacci0 + fibonacci1;
            fibonacci0 = fibonacci1;
            fibonacci1 = temp;
            i++;
        }
        return temp;
    }
}
